package com.cloud.system.api.web;

import com.cloud.system.api.bean.NoticeBean;
import com.cloud.system.api.bean.NoticeCriteriaBean;
import com.cloud.system.api.entity.Notice;
import com.cloud.system.api.service.NoticeService;
import com.cloud.system.common.result.Quokka;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;

@RestController
@RequestMapping("system/api/notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    /**
     *  分页加载收件箱通知数据
     * @param noticeCriteriaBean
     * @return
     */
    @PostMapping("loadreceivelist")
    public Quokka loadReceiveList(@RequestBody NoticeCriteriaBean noticeCriteriaBean) {
        return new Quokka(true,noticeService.loadReceiveList(noticeCriteriaBean));
    }

    /**
     * 分页加载发送箱通知数据
     * @param noticeCriteriaBean
     * @return
     */
    @PostMapping("loadpublishlist")
    public Quokka loadPublishList(@RequestBody NoticeCriteriaBean noticeCriteriaBean) {
        return new Quokka(true,noticeService.loadPublishList(noticeCriteriaBean));
    }

    /**
     * 发送通知角色
     * @return
     */
    @RequestMapping("loadroledata")
    public Quokka loadRoleData(){
        return new Quokka(true, noticeService.loadRoleData());
    }

    /**
     * 保存发布信息
     * @param noticeBean
     * @return
     */
    @RequestMapping("save")
    public Quokka save(@RequestBody NoticeBean noticeBean) {
        return new Quokka(true, noticeService.save(noticeBean));
    }

    /**
     * 根据主键删除通知
     * @param noticeId
     * @return
     */
    @RequestMapping("deletenoticebyid")
    public Quokka deleteNoticeById(int noticeId) {
        return new Quokka(true, noticeService.deleteNoticeById(noticeId));
    }

    /**
     * 首页加载通知信息
     * @return
     */
    @RequestMapping("loadnotice")
    public Quokka loadNotice() {
        return new Quokka(true, noticeService.loadNotice());
    }

    /**
     * 阅读回执
     * @param noticeId
     * @return
     */
    @RequestMapping("haveread")
    public Quokka haveRead(int noticeId) {
        return new Quokka(true,noticeService.haveRead(noticeId));
    }

    /**
     * 定时器，发送每周报表
     */
    @Scheduled(cron = "${jobs.cron}")
    public void autoSendNotice() throws IOException {
        noticeService.autoSendNotice();
    }

    /**
     * 公告编辑
     * @param noticeId
     * @return
     */
    @RequestMapping("loadnoticebyid")
    public Quokka loadNoticeById(int noticeId) {
        return new Quokka(true,noticeService.loadNoticeById(noticeId));
    }
}
